
//
//  EPMEmotionPageView.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/4/7.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "EPMEmotionPageView.h"
#import "EPMEmotionCell.h"

@interface EPMEmotionPageView()<UICollectionViewDataSource>

@end

@implementation EPMEmotionPageView

- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout{
    UICollectionViewFlowLayout* flowLayout = [UICollectionViewFlowLayout new];
    flowLayout.itemSize = frame.size;
    flowLayout.minimumLineSpacing = 0;
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    if (self = [super initWithFrame:frame collectionViewLayout:flowLayout]){
        [self setupUI];
    }
    return self;
}

#pragma
#pragma-设置UI
- (void)setupUI{
    self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"emoticon_keyboard_background"]];
    self.dataSource = self;
   
    [self registerClass:[EPMEmotionCell class] forCellWithReuseIdentifier:@"cell"];
    self.showsVerticalScrollIndicator = NO;
    self.showsHorizontalScrollIndicator = NO;
    self.pagingEnabled = YES;
    
    
}

#pragma
#pragma-数据源方法实现
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    NSMutableArray* temp = [EPMEmotionTool sheard].allEmotions;
    return  temp.count;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    NSArray* temp = [EPMEmotionTool sheard].allEmotions[section];
    
    return temp.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    EPMEmotionCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"emoticon_keyboard_background"]];
    NSArray* temp = [EPMEmotionTool sheard].allEmotions[indexPath.section];
    NSArray* emotionList = temp[indexPath.item];
    cell.emotionList = emotionList;
     cell.indexPath = indexPath;
    return cell;
}



@end
